{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "48e4b928",
   "metadata": {},
   "source": [
    "## Examining and selecting data from DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2bd2ac3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from IPython.display import display\n",
    "from openbb import obb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fdb23b0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "obb.user.preferences.output_type = \"dataframe\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54fb0589",
   "metadata": {},
   "source": [
    "Fetches historical price data for the equity \"AAPL\" starting from 2021-01-01 using the \"yfinance\" provider and stores it in 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ef955435",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = obb.equity.price.historical(\"AAPL\", start_date=\"2021-01-01\", provider=\"yfinance\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "35f37e70",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2531d21d",
   "metadata": {},
   "source": [
    "Displays the first 5 rows of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f134e090",
   "metadata": {},
   "outputs": [],
   "source": [
    "ddf = df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "728e0939",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7526a38",
   "metadata": {},
   "source": [
    "Displays the last 5 rows of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3aadf0d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "ddf = df.tail(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d5eaf513",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b58c806e",
   "metadata": {},
   "source": [
    "Displays the values of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e10e5172",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.33520004e+02, 1.33610001e+02, 1.26760002e+02, ...,\n",
       "        1.43301900e+08, 0.00000000e+00, 0.00000000e+00],\n",
       "       [1.28889999e+02, 1.31740005e+02, 1.28429993e+02, ...,\n",
       "        9.76649000e+07, 0.00000000e+00, 0.00000000e+00],\n",
       "       [1.27720001e+02, 1.31050003e+02, 1.26379997e+02, ...,\n",
       "        1.55088000e+08, 0.00000000e+00, 0.00000000e+00],\n",
       "       ...,\n",
       "       [2.07369995e+02, 2.20199997e+02, 2.06899994e+02, ...,\n",
       "        1.98134300e+08, 0.00000000e+00, 0.00000000e+00],\n",
       "       [2.14740005e+02, 2.16750000e+02, 2.11600006e+02, ...,\n",
       "        9.78627000e+07, 0.00000000e+00, 0.00000000e+00],\n",
       "       [2.13850006e+02, 2.15169998e+02, 2.11300003e+02, ...,\n",
       "        6.91756000e+07, 0.00000000e+00, 0.00000000e+00]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df.values)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dbe5d81",
   "metadata": {},
   "source": [
    "Displays the statistical summary of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b6bf3eab",
   "metadata": {},
   "outputs": [],
   "source": [
    "ddf = df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "18853788",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88c91f4b",
   "metadata": {},
   "source": [
    "Transposes 'df' and displays it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d75a552a",
   "metadata": {},
   "outputs": [],
   "source": [
    "ddf = df.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bb8e2908",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c2f9ed7",
   "metadata": {},
   "source": [
    "Displays the column names of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f0c0981f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['open', 'high', 'low', 'close', 'volume', 'split_ratio', 'dividend'], dtype='object')"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df.columns)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb395fe8",
   "metadata": {},
   "source": [
    "Updates the column names of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ed5e6d18",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.columns = [\n",
    "    \"open\",\n",
    "    \"high\",\n",
    "    \"low\",\n",
    "    \"close\",\n",
    "    \"volume\",\n",
    "    \"dividends\",\n",
    "    \"splits\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "076c2f63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>133.610001</td>\n",
       "      <td>126.760002</td>\n",
       "      <td>129.410004</td>\n",
       "      <td>143301900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "      <td>126.599998</td>\n",
       "      <td>155088000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>131.630005</td>\n",
       "      <td>127.860001</td>\n",
       "      <td>130.919998</td>\n",
       "      <td>109578200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.630005</td>\n",
       "      <td>130.229996</td>\n",
       "      <td>132.050003</td>\n",
       "      <td>105158200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-10</th>\n",
       "      <td>196.899994</td>\n",
       "      <td>197.300003</td>\n",
       "      <td>192.149994</td>\n",
       "      <td>193.119995</td>\n",
       "      <td>97262100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>193.649994</td>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "      <td>207.149994</td>\n",
       "      <td>172373300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-13</th>\n",
       "      <td>214.740005</td>\n",
       "      <td>216.750000</td>\n",
       "      <td>211.600006</td>\n",
       "      <td>214.240005</td>\n",
       "      <td>97862700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-14</th>\n",
       "      <td>213.850006</td>\n",
       "      <td>215.169998</td>\n",
       "      <td>211.300003</td>\n",
       "      <td>212.490005</td>\n",
       "      <td>69175600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>868 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-04  133.520004  133.610001  126.760002  129.410004  143301900   \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-06  127.720001  131.050003  126.379997  126.599998  155088000   \n",
       "2021-01-07  128.360001  131.630005  127.860001  130.919998  109578200   \n",
       "2021-01-08  132.429993  132.630005  130.229996  132.050003  105158200   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2024-06-10  196.899994  197.300003  192.149994  193.119995   97262100   \n",
       "2024-06-11  193.649994  207.160004  193.630005  207.149994  172373300   \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "2024-06-13  214.740005  216.750000  211.600006  214.240005   97862700   \n",
       "2024-06-14  213.850006  215.169998  211.300003  212.490005   69175600   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-04        0.0     0.0  \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-06        0.0     0.0  \n",
       "2021-01-07        0.0     0.0  \n",
       "2021-01-08        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2024-06-10        0.0     0.0  \n",
       "2024-06-11        0.0     0.0  \n",
       "2024-06-12        0.0     0.0  \n",
       "2024-06-13        0.0     0.0  \n",
       "2024-06-14        0.0     0.0  \n",
       "\n",
       "[868 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82b9f108",
   "metadata": {},
   "source": [
    "Accesses the 'close' column using two different methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e6ad0a1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2021-01-04    129.410004\n",
       "2021-01-05    131.009995\n",
       "2021-01-06    126.599998\n",
       "2021-01-07    130.919998\n",
       "2021-01-08    132.050003\n",
       "                 ...    \n",
       "2024-06-10    193.119995\n",
       "2024-06-11    207.149994\n",
       "2024-06-12    213.070007\n",
       "2024-06-13    214.240005\n",
       "2024-06-14    212.490005\n",
       "Name: close, Length: 868, dtype: float64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"close\"]\n",
    "df.close"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "035c4ff3",
   "metadata": {},
   "source": [
    "Slices the first three rows of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5f4b53ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>133.610001</td>\n",
       "      <td>126.760002</td>\n",
       "      <td>129.410004</td>\n",
       "      <td>143301900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "      <td>126.599998</td>\n",
       "      <td>155088000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-04  133.520004  133.610001  126.760002  129.410004  143301900   \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-06  127.720001  131.050003  126.379997  126.599998  155088000   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-04        0.0     0.0  \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-06        0.0     0.0  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[0:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c91e8f71",
   "metadata": {},
   "source": [
    "Slices 'df' by date range (inclusive of the last value) after converting the index to datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "280f1d90",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>133.610001</td>\n",
       "      <td>126.760002</td>\n",
       "      <td>129.410004</td>\n",
       "      <td>143301900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "      <td>126.599998</td>\n",
       "      <td>155088000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>131.630005</td>\n",
       "      <td>127.860001</td>\n",
       "      <td>130.919998</td>\n",
       "      <td>109578200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.630005</td>\n",
       "      <td>130.229996</td>\n",
       "      <td>132.050003</td>\n",
       "      <td>105158200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-11</th>\n",
       "      <td>129.190002</td>\n",
       "      <td>130.169998</td>\n",
       "      <td>128.500000</td>\n",
       "      <td>128.979996</td>\n",
       "      <td>100384500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-04  133.520004  133.610001  126.760002  129.410004  143301900   \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-06  127.720001  131.050003  126.379997  126.599998  155088000   \n",
       "2021-01-07  128.360001  131.630005  127.860001  130.919998  109578200   \n",
       "2021-01-08  132.429993  132.630005  130.229996  132.050003  105158200   \n",
       "2021-01-11  129.190002  130.169998  128.500000  128.979996  100384500   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-04        0.0     0.0  \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-06        0.0     0.0  \n",
       "2021-01-07        0.0     0.0  \n",
       "2021-01-08        0.0     0.0  \n",
       "2021-01-11        0.0     0.0  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index = pd.to_datetime(df.index)\n",
    "df[\"2021-01-02\":\"2021-01-11\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4543e4f3",
   "metadata": {},
   "source": [
    "Displays the index (dates) of 'df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "32302b92",
   "metadata": {},
   "outputs": [],
   "source": [
    "dates = df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "a27d99c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46afbe64",
   "metadata": {},
   "source": [
    "Accesses the first date in the index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "47d53bc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2021-01-04 00:00:00')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "868adb73",
   "metadata": {},
   "source": [
    "Accesses the row corresponding to the first date in the index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d8cbaae3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open         1.335200e+02\n",
       "high         1.336100e+02\n",
       "low          1.267600e+02\n",
       "close        1.294100e+02\n",
       "volume       1.433019e+08\n",
       "dividends    0.000000e+00\n",
       "splits       0.000000e+00\n",
       "Name: 2021-01-04 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df.index[0]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ce4d200",
   "metadata": {},
   "source": [
    "Accesses the 'close' value for the first date in the index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "026a45f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "129.41000366210938"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df.index[0], \"close\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4957379",
   "metadata": {},
   "source": [
    "Accesses the 'open' and 'close' values for the first date in the index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "01424d5d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open     133.520004\n",
       "close    129.410004\n",
       "Name: 2021-01-04 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df.index[0], [\"open\", \"close\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "031bba40",
   "metadata": {},
   "source": [
    "Slices the first six rows and selects the 'open' and 'close' columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6f584ec7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>129.410004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.009995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>126.599998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>130.919998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.050003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-11</th>\n",
       "      <td>129.190002</td>\n",
       "      <td>128.979996</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open       close\n",
       "date                              \n",
       "2021-01-04  133.520004  129.410004\n",
       "2021-01-05  128.889999  131.009995\n",
       "2021-01-06  127.720001  126.599998\n",
       "2021-01-07  128.360001  130.919998\n",
       "2021-01-08  132.429993  132.050003\n",
       "2021-01-11  129.190002  128.979996"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df.index[0:6], [\"open\", \"close\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75ab1878",
   "metadata": {},
   "source": [
    "Slices 'df' by date range and selects the 'open' and 'close' columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "4b180d31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>129.410004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.009995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>126.599998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>130.919998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.050003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-11</th>\n",
       "      <td>129.190002</td>\n",
       "      <td>128.979996</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open       close\n",
       "date                              \n",
       "2021-01-04  133.520004  129.410004\n",
       "2021-01-05  128.889999  131.009995\n",
       "2021-01-06  127.720001  126.599998\n",
       "2021-01-07  128.360001  130.919998\n",
       "2021-01-08  132.429993  132.050003\n",
       "2021-01-11  129.190002  128.979996"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\"2021-01-02\":\"2021-01-11\", [\"open\", \"close\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "304a1cb9",
   "metadata": {},
   "source": [
    "Accesses the fourth row of 'df' using integer location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f7b128fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open         1.283600e+02\n",
       "high         1.316300e+02\n",
       "low          1.278600e+02\n",
       "close        1.309200e+02\n",
       "volume       1.095782e+08\n",
       "dividends    0.000000e+00\n",
       "splits       0.000000e+00\n",
       "Name: 2021-01-07 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f40e4ea",
   "metadata": {},
   "source": [
    "Slices the third and fourth rows and the first two columns using integer location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "48a1d7fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>131.630005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.630005</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high\n",
       "date                              \n",
       "2021-01-07  128.360001  131.630005\n",
       "2021-01-08  132.429993  132.630005"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3:5, 0:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a5e0630",
   "metadata": {},
   "source": [
    "Selects specific rows and columns by integer position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "385328b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>low</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>128.429993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>126.379997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>130.229996</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open         low\n",
       "date                              \n",
       "2021-01-05  128.889999  128.429993\n",
       "2021-01-06  127.720001  126.379997\n",
       "2021-01-08  132.429993  130.229996"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[[1, 2, 4], [0, 2]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6126b6a",
   "metadata": {},
   "source": [
    "Slices rows explicitly using integer location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "386cad0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "      <td>126.599998</td>\n",
       "      <td>155088000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-06  127.720001  131.050003  126.379997  126.599998  155088000   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-06        0.0     0.0  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[1:3, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3eeebc2b",
   "metadata": {},
   "source": [
    "Slices columns explicitly using integer location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "c81745a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.610001</td>\n",
       "      <td>126.760002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>131.630005</td>\n",
       "      <td>127.860001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.630005</td>\n",
       "      <td>130.229996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-10</th>\n",
       "      <td>197.300003</td>\n",
       "      <td>192.149994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-13</th>\n",
       "      <td>216.750000</td>\n",
       "      <td>211.600006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-14</th>\n",
       "      <td>215.169998</td>\n",
       "      <td>211.300003</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>868 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  high         low\n",
       "date                              \n",
       "2021-01-04  133.610001  126.760002\n",
       "2021-01-05  131.740005  128.429993\n",
       "2021-01-06  131.050003  126.379997\n",
       "2021-01-07  131.630005  127.860001\n",
       "2021-01-08  132.630005  130.229996\n",
       "...                ...         ...\n",
       "2024-06-10  197.300003  192.149994\n",
       "2024-06-11  207.160004  193.630005\n",
       "2024-06-12  220.199997  206.899994\n",
       "2024-06-13  216.750000  211.600006\n",
       "2024-06-14  215.169998  211.300003\n",
       "\n",
       "[868 rows x 2 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:, 1:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b881bfcb",
   "metadata": {},
   "source": [
    "Accesses a specific value using integer location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "9668d7ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "131.74000549316406"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[1, 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20ff5b25",
   "metadata": {},
   "source": [
    "Accesses a specific value using fast access method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a2e9f19c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "131.74000549316406"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iat[1, 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9237b870",
   "metadata": {},
   "source": [
    "Uses boolean indexing to select data where 'close' is greater than the mean 'close' value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "3fc7fed5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2021-01-04    False\n",
       "2021-01-05    False\n",
       "2021-01-06    False\n",
       "2021-01-07    False\n",
       "2021-01-08    False\n",
       "              ...  \n",
       "2024-06-10     True\n",
       "2024-06-11     True\n",
       "2024-06-12     True\n",
       "2024-06-13     True\n",
       "2024-06-14     True\n",
       "Name: close, Length: 868, dtype: bool"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.close > df.close.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "83c495b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-11-19</th>\n",
       "      <td>157.649994</td>\n",
       "      <td>161.020004</td>\n",
       "      <td>156.529999</td>\n",
       "      <td>160.550003</td>\n",
       "      <td>117305600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-22</th>\n",
       "      <td>161.679993</td>\n",
       "      <td>165.699997</td>\n",
       "      <td>161.000000</td>\n",
       "      <td>161.020004</td>\n",
       "      <td>117467900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-23</th>\n",
       "      <td>161.119995</td>\n",
       "      <td>161.800003</td>\n",
       "      <td>159.059998</td>\n",
       "      <td>161.410004</td>\n",
       "      <td>96041900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-24</th>\n",
       "      <td>160.750000</td>\n",
       "      <td>162.139999</td>\n",
       "      <td>159.639999</td>\n",
       "      <td>161.940002</td>\n",
       "      <td>69463600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-29</th>\n",
       "      <td>159.369995</td>\n",
       "      <td>161.190002</td>\n",
       "      <td>158.789993</td>\n",
       "      <td>160.240005</td>\n",
       "      <td>88748200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-10</th>\n",
       "      <td>196.899994</td>\n",
       "      <td>197.300003</td>\n",
       "      <td>192.149994</td>\n",
       "      <td>193.119995</td>\n",
       "      <td>97262100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>193.649994</td>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "      <td>207.149994</td>\n",
       "      <td>172373300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-13</th>\n",
       "      <td>214.740005</td>\n",
       "      <td>216.750000</td>\n",
       "      <td>211.600006</td>\n",
       "      <td>214.240005</td>\n",
       "      <td>97862700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-14</th>\n",
       "      <td>213.850006</td>\n",
       "      <td>215.169998</td>\n",
       "      <td>211.300003</td>\n",
       "      <td>212.490005</td>\n",
       "      <td>69175600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>431 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-11-19  157.649994  161.020004  156.529999  160.550003  117305600   \n",
       "2021-11-22  161.679993  165.699997  161.000000  161.020004  117467900   \n",
       "2021-11-23  161.119995  161.800003  159.059998  161.410004   96041900   \n",
       "2021-11-24  160.750000  162.139999  159.639999  161.940002   69463600   \n",
       "2021-11-29  159.369995  161.190002  158.789993  160.240005   88748200   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2024-06-10  196.899994  197.300003  192.149994  193.119995   97262100   \n",
       "2024-06-11  193.649994  207.160004  193.630005  207.149994  172373300   \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "2024-06-13  214.740005  216.750000  211.600006  214.240005   97862700   \n",
       "2024-06-14  213.850006  215.169998  211.300003  212.490005   69175600   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-11-19        0.0     0.0  \n",
       "2021-11-22        0.0     0.0  \n",
       "2021-11-23        0.0     0.0  \n",
       "2021-11-24        0.0     0.0  \n",
       "2021-11-29        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2024-06-10        0.0     0.0  \n",
       "2024-06-11        0.0     0.0  \n",
       "2024-06-12        0.0     0.0  \n",
       "2024-06-13        0.0     0.0  \n",
       "2024-06-14        0.0     0.0  \n",
       "\n",
       "[431 rows x 7 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.close > df.close.mean()]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54bb284c",
   "metadata": {},
   "source": [
    "Selects the first column where 'close' is greater than the mean 'close' value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "d865ef5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2021-11-19    157.649994\n",
       "2021-11-22    161.679993\n",
       "2021-11-23    161.119995\n",
       "2021-11-24    160.750000\n",
       "2021-11-29    159.369995\n",
       "                 ...    \n",
       "2024-06-10    196.899994\n",
       "2024-06-11    193.649994\n",
       "2024-06-12    207.369995\n",
       "2024-06-13    214.740005\n",
       "2024-06-14    213.850006\n",
       "Name: open, Length: 431, dtype: float64"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.close > df.close.mean()].iloc[:, 0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1a448ab",
   "metadata": {},
   "source": [
    "Uses multiple conditions to filter the DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "1589d382",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-11-19</th>\n",
       "      <td>157.649994</td>\n",
       "      <td>161.020004</td>\n",
       "      <td>156.529999</td>\n",
       "      <td>160.550003</td>\n",
       "      <td>117305600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-22</th>\n",
       "      <td>161.679993</td>\n",
       "      <td>165.699997</td>\n",
       "      <td>161.000000</td>\n",
       "      <td>161.020004</td>\n",
       "      <td>117467900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-23</th>\n",
       "      <td>161.119995</td>\n",
       "      <td>161.800003</td>\n",
       "      <td>159.059998</td>\n",
       "      <td>161.410004</td>\n",
       "      <td>96041900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-29</th>\n",
       "      <td>159.369995</td>\n",
       "      <td>161.190002</td>\n",
       "      <td>158.789993</td>\n",
       "      <td>160.240005</td>\n",
       "      <td>88748200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-30</th>\n",
       "      <td>159.990005</td>\n",
       "      <td>165.520004</td>\n",
       "      <td>159.919998</td>\n",
       "      <td>165.300003</td>\n",
       "      <td>174048100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-05-07</th>\n",
       "      <td>183.449997</td>\n",
       "      <td>184.899994</td>\n",
       "      <td>181.320007</td>\n",
       "      <td>182.399994</td>\n",
       "      <td>77305800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-10</th>\n",
       "      <td>196.899994</td>\n",
       "      <td>197.300003</td>\n",
       "      <td>192.149994</td>\n",
       "      <td>193.119995</td>\n",
       "      <td>97262100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>193.649994</td>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "      <td>207.149994</td>\n",
       "      <td>172373300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-13</th>\n",
       "      <td>214.740005</td>\n",
       "      <td>216.750000</td>\n",
       "      <td>211.600006</td>\n",
       "      <td>214.240005</td>\n",
       "      <td>97862700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>117 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-11-19  157.649994  161.020004  156.529999  160.550003  117305600   \n",
       "2021-11-22  161.679993  165.699997  161.000000  161.020004  117467900   \n",
       "2021-11-23  161.119995  161.800003  159.059998  161.410004   96041900   \n",
       "2021-11-29  159.369995  161.190002  158.789993  160.240005   88748200   \n",
       "2021-11-30  159.990005  165.520004  159.919998  165.300003  174048100   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2024-05-07  183.449997  184.899994  181.320007  182.399994   77305800   \n",
       "2024-06-10  196.899994  197.300003  192.149994  193.119995   97262100   \n",
       "2024-06-11  193.649994  207.160004  193.630005  207.149994  172373300   \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "2024-06-13  214.740005  216.750000  211.600006  214.240005   97862700   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-11-19        0.0     0.0  \n",
       "2021-11-22        0.0     0.0  \n",
       "2021-11-23        0.0     0.0  \n",
       "2021-11-29        0.0     0.0  \n",
       "2021-11-30        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2024-05-07        0.0     0.0  \n",
       "2024-06-10        0.0     0.0  \n",
       "2024-06-11        0.0     0.0  \n",
       "2024-06-12        0.0     0.0  \n",
       "2024-06-13        0.0     0.0  \n",
       "\n",
       "[117 rows x 7 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    (df.close > df.close.mean())\n",
    "    & (df.close.mean() > 100)\n",
    "    & (df.volume > df.volume.mean())\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c42716dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>133.520004</td>\n",
       "      <td>133.610001</td>\n",
       "      <td>126.760002</td>\n",
       "      <td>129.410004</td>\n",
       "      <td>143301900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>127.720001</td>\n",
       "      <td>131.050003</td>\n",
       "      <td>126.379997</td>\n",
       "      <td>126.599998</td>\n",
       "      <td>155088000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>131.630005</td>\n",
       "      <td>127.860001</td>\n",
       "      <td>130.919998</td>\n",
       "      <td>109578200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-08</th>\n",
       "      <td>132.429993</td>\n",
       "      <td>132.630005</td>\n",
       "      <td>130.229996</td>\n",
       "      <td>132.050003</td>\n",
       "      <td>105158200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-10</th>\n",
       "      <td>196.899994</td>\n",
       "      <td>197.300003</td>\n",
       "      <td>192.149994</td>\n",
       "      <td>193.119995</td>\n",
       "      <td>97262100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>193.649994</td>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "      <td>207.149994</td>\n",
       "      <td>172373300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-13</th>\n",
       "      <td>214.740005</td>\n",
       "      <td>216.750000</td>\n",
       "      <td>211.600006</td>\n",
       "      <td>214.240005</td>\n",
       "      <td>97862700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-14</th>\n",
       "      <td>213.850006</td>\n",
       "      <td>215.169998</td>\n",
       "      <td>211.300003</td>\n",
       "      <td>212.490005</td>\n",
       "      <td>69175600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>868 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-04  133.520004  133.610001  126.760002  129.410004  143301900   \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-06  127.720001  131.050003  126.379997  126.599998  155088000   \n",
       "2021-01-07  128.360001  131.630005  127.860001  130.919998  109578200   \n",
       "2021-01-08  132.429993  132.630005  130.229996  132.050003  105158200   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2024-06-10  196.899994  197.300003  192.149994  193.119995   97262100   \n",
       "2024-06-11  193.649994  207.160004  193.630005  207.149994  172373300   \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "2024-06-13  214.740005  216.750000  211.600006  214.240005   97862700   \n",
       "2024-06-14  213.850006  215.169998  211.300003  212.490005   69175600   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-04        0.0     0.0  \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-06        0.0     0.0  \n",
       "2021-01-07        0.0     0.0  \n",
       "2021-01-08        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2024-06-10        0.0     0.0  \n",
       "2024-06-11        0.0     0.0  \n",
       "2024-06-12        0.0     0.0  \n",
       "2024-06-13        0.0     0.0  \n",
       "2024-06-14        0.0     0.0  \n",
       "\n",
       "[868 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7ca30e0",
   "metadata": {},
   "source": [
    "Selects rows from the year 2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "94a2ee0a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-01-03</th>\n",
       "      <td>130.279999</td>\n",
       "      <td>130.899994</td>\n",
       "      <td>124.169998</td>\n",
       "      <td>125.070000</td>\n",
       "      <td>112117500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-01-04</th>\n",
       "      <td>126.889999</td>\n",
       "      <td>128.660004</td>\n",
       "      <td>125.080002</td>\n",
       "      <td>126.360001</td>\n",
       "      <td>89113600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-01-05</th>\n",
       "      <td>127.129997</td>\n",
       "      <td>127.769997</td>\n",
       "      <td>124.760002</td>\n",
       "      <td>125.019997</td>\n",
       "      <td>80962700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-01-06</th>\n",
       "      <td>126.010002</td>\n",
       "      <td>130.289993</td>\n",
       "      <td>124.889999</td>\n",
       "      <td>129.619995</td>\n",
       "      <td>87754700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-01-09</th>\n",
       "      <td>130.470001</td>\n",
       "      <td>133.410004</td>\n",
       "      <td>129.889999</td>\n",
       "      <td>130.149994</td>\n",
       "      <td>70790800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>192.970001</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>37122800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-26</th>\n",
       "      <td>193.610001</td>\n",
       "      <td>193.889999</td>\n",
       "      <td>192.830002</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>28919300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-27</th>\n",
       "      <td>192.490005</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>191.089996</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>48087700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-28</th>\n",
       "      <td>194.139999</td>\n",
       "      <td>194.660004</td>\n",
       "      <td>193.169998</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>34049900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29</th>\n",
       "      <td>193.899994</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>191.729996</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>42628800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>250 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2023-01-03  130.279999  130.899994  124.169998  125.070000  112117500   \n",
       "2023-01-04  126.889999  128.660004  125.080002  126.360001   89113600   \n",
       "2023-01-05  127.129997  127.769997  124.760002  125.019997   80962700   \n",
       "2023-01-06  126.010002  130.289993  124.889999  129.619995   87754700   \n",
       "2023-01-09  130.470001  133.410004  129.889999  130.149994   70790800   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2023-12-22  195.179993  195.410004  192.970001  193.600006   37122800   \n",
       "2023-12-26  193.610001  193.889999  192.830002  193.050003   28919300   \n",
       "2023-12-27  192.490005  193.500000  191.089996  193.149994   48087700   \n",
       "2023-12-28  194.139999  194.660004  193.169998  193.580002   34049900   \n",
       "2023-12-29  193.899994  194.399994  191.729996  192.529999   42628800   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2023-01-03        0.0     0.0  \n",
       "2023-01-04        0.0     0.0  \n",
       "2023-01-05        0.0     0.0  \n",
       "2023-01-06        0.0     0.0  \n",
       "2023-01-09        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2023-12-22        0.0     0.0  \n",
       "2023-12-26        0.0     0.0  \n",
       "2023-12-27        0.0     0.0  \n",
       "2023-12-28        0.0     0.0  \n",
       "2023-12-29        0.0     0.0  \n",
       "\n",
       "[250 rows x 7 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\"2023\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00c899bb",
   "metadata": {},
   "source": [
    "Selects rows from July 2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "0acef058",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-07-03</th>\n",
       "      <td>193.779999</td>\n",
       "      <td>193.880005</td>\n",
       "      <td>191.759995</td>\n",
       "      <td>192.460007</td>\n",
       "      <td>31458200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-05</th>\n",
       "      <td>191.570007</td>\n",
       "      <td>192.979996</td>\n",
       "      <td>190.619995</td>\n",
       "      <td>191.330002</td>\n",
       "      <td>46920300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-06</th>\n",
       "      <td>189.839996</td>\n",
       "      <td>192.020004</td>\n",
       "      <td>189.199997</td>\n",
       "      <td>191.809998</td>\n",
       "      <td>45094300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-07</th>\n",
       "      <td>191.410004</td>\n",
       "      <td>192.669998</td>\n",
       "      <td>190.240005</td>\n",
       "      <td>190.679993</td>\n",
       "      <td>46778000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-10</th>\n",
       "      <td>189.259995</td>\n",
       "      <td>189.990005</td>\n",
       "      <td>187.039993</td>\n",
       "      <td>188.610001</td>\n",
       "      <td>59922200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-11</th>\n",
       "      <td>189.160004</td>\n",
       "      <td>189.300003</td>\n",
       "      <td>186.600006</td>\n",
       "      <td>188.080002</td>\n",
       "      <td>46638100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-12</th>\n",
       "      <td>189.679993</td>\n",
       "      <td>191.699997</td>\n",
       "      <td>188.470001</td>\n",
       "      <td>189.770004</td>\n",
       "      <td>60750200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-13</th>\n",
       "      <td>190.500000</td>\n",
       "      <td>191.190002</td>\n",
       "      <td>189.779999</td>\n",
       "      <td>190.539993</td>\n",
       "      <td>41342300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-14</th>\n",
       "      <td>190.229996</td>\n",
       "      <td>191.179993</td>\n",
       "      <td>189.630005</td>\n",
       "      <td>190.690002</td>\n",
       "      <td>41573900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-17</th>\n",
       "      <td>191.899994</td>\n",
       "      <td>194.320007</td>\n",
       "      <td>191.809998</td>\n",
       "      <td>193.990005</td>\n",
       "      <td>50520200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-18</th>\n",
       "      <td>193.350006</td>\n",
       "      <td>194.330002</td>\n",
       "      <td>192.419998</td>\n",
       "      <td>193.729996</td>\n",
       "      <td>48353800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-19</th>\n",
       "      <td>193.100006</td>\n",
       "      <td>198.229996</td>\n",
       "      <td>192.649994</td>\n",
       "      <td>195.100006</td>\n",
       "      <td>80507300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-20</th>\n",
       "      <td>195.089996</td>\n",
       "      <td>196.470001</td>\n",
       "      <td>192.500000</td>\n",
       "      <td>193.130005</td>\n",
       "      <td>59581200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-21</th>\n",
       "      <td>194.100006</td>\n",
       "      <td>194.970001</td>\n",
       "      <td>191.229996</td>\n",
       "      <td>191.940002</td>\n",
       "      <td>71917800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-24</th>\n",
       "      <td>193.410004</td>\n",
       "      <td>194.910004</td>\n",
       "      <td>192.250000</td>\n",
       "      <td>192.750000</td>\n",
       "      <td>45377800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-25</th>\n",
       "      <td>193.330002</td>\n",
       "      <td>194.440002</td>\n",
       "      <td>192.919998</td>\n",
       "      <td>193.619995</td>\n",
       "      <td>37283200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-26</th>\n",
       "      <td>193.669998</td>\n",
       "      <td>195.639999</td>\n",
       "      <td>193.320007</td>\n",
       "      <td>194.500000</td>\n",
       "      <td>47471900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-27</th>\n",
       "      <td>196.020004</td>\n",
       "      <td>197.199997</td>\n",
       "      <td>192.550003</td>\n",
       "      <td>193.220001</td>\n",
       "      <td>47460200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-28</th>\n",
       "      <td>194.669998</td>\n",
       "      <td>196.630005</td>\n",
       "      <td>194.139999</td>\n",
       "      <td>195.830002</td>\n",
       "      <td>48291400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-07-31</th>\n",
       "      <td>196.059998</td>\n",
       "      <td>196.490005</td>\n",
       "      <td>195.259995</td>\n",
       "      <td>196.449997</td>\n",
       "      <td>38824100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close    volume  \\\n",
       "date                                                                   \n",
       "2023-07-03  193.779999  193.880005  191.759995  192.460007  31458200   \n",
       "2023-07-05  191.570007  192.979996  190.619995  191.330002  46920300   \n",
       "2023-07-06  189.839996  192.020004  189.199997  191.809998  45094300   \n",
       "2023-07-07  191.410004  192.669998  190.240005  190.679993  46778000   \n",
       "2023-07-10  189.259995  189.990005  187.039993  188.610001  59922200   \n",
       "2023-07-11  189.160004  189.300003  186.600006  188.080002  46638100   \n",
       "2023-07-12  189.679993  191.699997  188.470001  189.770004  60750200   \n",
       "2023-07-13  190.500000  191.190002  189.779999  190.539993  41342300   \n",
       "2023-07-14  190.229996  191.179993  189.630005  190.690002  41573900   \n",
       "2023-07-17  191.899994  194.320007  191.809998  193.990005  50520200   \n",
       "2023-07-18  193.350006  194.330002  192.419998  193.729996  48353800   \n",
       "2023-07-19  193.100006  198.229996  192.649994  195.100006  80507300   \n",
       "2023-07-20  195.089996  196.470001  192.500000  193.130005  59581200   \n",
       "2023-07-21  194.100006  194.970001  191.229996  191.940002  71917800   \n",
       "2023-07-24  193.410004  194.910004  192.250000  192.750000  45377800   \n",
       "2023-07-25  193.330002  194.440002  192.919998  193.619995  37283200   \n",
       "2023-07-26  193.669998  195.639999  193.320007  194.500000  47471900   \n",
       "2023-07-27  196.020004  197.199997  192.550003  193.220001  47460200   \n",
       "2023-07-28  194.669998  196.630005  194.139999  195.830002  48291400   \n",
       "2023-07-31  196.059998  196.490005  195.259995  196.449997  38824100   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2023-07-03        0.0     0.0  \n",
       "2023-07-05        0.0     0.0  \n",
       "2023-07-06        0.0     0.0  \n",
       "2023-07-07        0.0     0.0  \n",
       "2023-07-10        0.0     0.0  \n",
       "2023-07-11        0.0     0.0  \n",
       "2023-07-12        0.0     0.0  \n",
       "2023-07-13        0.0     0.0  \n",
       "2023-07-14        0.0     0.0  \n",
       "2023-07-17        0.0     0.0  \n",
       "2023-07-18        0.0     0.0  \n",
       "2023-07-19        0.0     0.0  \n",
       "2023-07-20        0.0     0.0  \n",
       "2023-07-21        0.0     0.0  \n",
       "2023-07-24        0.0     0.0  \n",
       "2023-07-25        0.0     0.0  \n",
       "2023-07-26        0.0     0.0  \n",
       "2023-07-27        0.0     0.0  \n",
       "2023-07-28        0.0     0.0  \n",
       "2023-07-31        0.0     0.0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\"2023-07\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba5bb1d2",
   "metadata": {},
   "source": [
    "Accesses the 'close' value on 2023-07-12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bc9a3f1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "189.77000427246094"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.at[\"2023-07-12\", \"close\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cb13d2b8",
   "metadata": {},
   "source": [
    "Selects the top 5 rows with the highest 'volume'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "6e54b327",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-17</th>\n",
       "      <td>169.929993</td>\n",
       "      <td>173.470001</td>\n",
       "      <td>169.690002</td>\n",
       "      <td>171.139999</td>\n",
       "      <td>195432700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-03-19</th>\n",
       "      <td>119.900002</td>\n",
       "      <td>121.430000</td>\n",
       "      <td>119.680000</td>\n",
       "      <td>119.989998</td>\n",
       "      <td>185549500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-12</th>\n",
       "      <td>142.770004</td>\n",
       "      <td>146.199997</td>\n",
       "      <td>138.800003</td>\n",
       "      <td>142.559998</td>\n",
       "      <td>182602000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-01-28</th>\n",
       "      <td>165.710007</td>\n",
       "      <td>170.350006</td>\n",
       "      <td>162.800003</td>\n",
       "      <td>170.330002</td>\n",
       "      <td>179935700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "2021-12-17  169.929993  173.470001  169.690002  171.139999  195432700   \n",
       "2021-03-19  119.900002  121.430000  119.680000  119.989998  185549500   \n",
       "2022-05-12  142.770004  146.199997  138.800003  142.559998  182602000   \n",
       "2022-01-28  165.710007  170.350006  162.800003  170.330002  179935700   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2024-06-12        0.0     0.0  \n",
       "2021-12-17        0.0     0.0  \n",
       "2021-03-19        0.0     0.0  \n",
       "2022-05-12        0.0     0.0  \n",
       "2022-01-28        0.0     0.0  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.nlargest(5, \"volume\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0dc2686",
   "metadata": {},
   "source": [
    "Queries the DataFrame to select rows where 'close' is greater than 'open'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "a34ed9e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>dividends</th>\n",
       "      <th>splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>128.889999</td>\n",
       "      <td>131.740005</td>\n",
       "      <td>128.429993</td>\n",
       "      <td>131.009995</td>\n",
       "      <td>97664900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>128.360001</td>\n",
       "      <td>131.630005</td>\n",
       "      <td>127.860001</td>\n",
       "      <td>130.919998</td>\n",
       "      <td>109578200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-12</th>\n",
       "      <td>128.500000</td>\n",
       "      <td>129.690002</td>\n",
       "      <td>126.860001</td>\n",
       "      <td>128.800003</td>\n",
       "      <td>91951100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-13</th>\n",
       "      <td>128.759995</td>\n",
       "      <td>131.449997</td>\n",
       "      <td>128.490005</td>\n",
       "      <td>130.889999</td>\n",
       "      <td>88636800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-19</th>\n",
       "      <td>127.779999</td>\n",
       "      <td>128.710007</td>\n",
       "      <td>126.940002</td>\n",
       "      <td>127.830002</td>\n",
       "      <td>90757300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-03</th>\n",
       "      <td>192.899994</td>\n",
       "      <td>194.990005</td>\n",
       "      <td>192.520004</td>\n",
       "      <td>194.029999</td>\n",
       "      <td>50080500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-05</th>\n",
       "      <td>195.399994</td>\n",
       "      <td>196.899994</td>\n",
       "      <td>194.869995</td>\n",
       "      <td>195.869995</td>\n",
       "      <td>54156800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-07</th>\n",
       "      <td>194.649994</td>\n",
       "      <td>196.940002</td>\n",
       "      <td>194.139999</td>\n",
       "      <td>196.889999</td>\n",
       "      <td>53103900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-11</th>\n",
       "      <td>193.649994</td>\n",
       "      <td>207.160004</td>\n",
       "      <td>193.630005</td>\n",
       "      <td>207.149994</td>\n",
       "      <td>172373300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-12</th>\n",
       "      <td>207.369995</td>\n",
       "      <td>220.199997</td>\n",
       "      <td>206.899994</td>\n",
       "      <td>213.070007</td>\n",
       "      <td>198134300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>457 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  open        high         low       close     volume  \\\n",
       "date                                                                    \n",
       "2021-01-05  128.889999  131.740005  128.429993  131.009995   97664900   \n",
       "2021-01-07  128.360001  131.630005  127.860001  130.919998  109578200   \n",
       "2021-01-12  128.500000  129.690002  126.860001  128.800003   91951100   \n",
       "2021-01-13  128.759995  131.449997  128.490005  130.889999   88636800   \n",
       "2021-01-19  127.779999  128.710007  126.940002  127.830002   90757300   \n",
       "...                ...         ...         ...         ...        ...   \n",
       "2024-06-03  192.899994  194.990005  192.520004  194.029999   50080500   \n",
       "2024-06-05  195.399994  196.899994  194.869995  195.869995   54156800   \n",
       "2024-06-07  194.649994  196.940002  194.139999  196.889999   53103900   \n",
       "2024-06-11  193.649994  207.160004  193.630005  207.149994  172373300   \n",
       "2024-06-12  207.369995  220.199997  206.899994  213.070007  198134300   \n",
       "\n",
       "            dividends  splits  \n",
       "date                           \n",
       "2021-01-05        0.0     0.0  \n",
       "2021-01-07        0.0     0.0  \n",
       "2021-01-12        0.0     0.0  \n",
       "2021-01-13        0.0     0.0  \n",
       "2021-01-19        0.0     0.0  \n",
       "...               ...     ...  \n",
       "2024-06-03        0.0     0.0  \n",
       "2024-06-05        0.0     0.0  \n",
       "2024-06-07        0.0     0.0  \n",
       "2024-06-11        0.0     0.0  \n",
       "2024-06-12        0.0     0.0  \n",
       "\n",
       "[457 rows x 7 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query(\"close > open\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bfebf0d",
   "metadata": {},
   "source": [
    "**Jason Strimpel** is the founder of <a href='https://pyquantnews.com/'>PyQuant News</a> and co-founder of <a href='https://www.tradeblotter.io/'>Trade Blotter</a>. His career in algorithmic trading spans 20+ years. He previously traded for a Chicago-based hedge fund, was a risk manager at JPMorgan, and managed production risk technology for an energy derivatives trading firm in London. In Singapore, he served as APAC CIO for an agricultural trading firm and built the data science team for a global metals trading firm. Jason holds degrees in Finance and Economics and a Master's in Quantitative Finance from the Illinois Institute of Technology. His career spans America, Europe, and Asia. He shares his expertise through the <a href='https://pyquantnews.com/subscribe-to-the-pyquant-newsletter/'>PyQuant Newsletter</a>, social media, and has taught over 1,000+ algorithmic trading with Python in his popular course **<a href='https://gettingstartedwithpythonforquantfinance.com/'>Getting Started With Python for Quant Finance</a>**. All code is for educational purposes only. Nothing provided here is financial advise. Use at your own risk."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52711468-1fd0-4d9b-b6cc-06d8c299a0ce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
